package org.agile4j.math.recursion;

import java.util.ArrayList;

public class RecursionDemo02 {

    /**
     * @param product 乘积
     * @param result
     */
    public static void get(long product, ArrayList<Long> result) {
        // 循环最后一步，既等于指定整数时退出递归
        if (product == 1) {
            if (!result.contains(1L)) {
                result.add(product);
            }
            System.out.println(result);
            return;
        } else {
            for (long i = 1L; i <= product; i++) {
                if ((i == 1L) && result.contains(1L)) {
                    continue;
                }
                ArrayList<Long> newList = (ArrayList<Long>) (result.clone());
                newList.add(i);
                // 只有余数为零时，乘积才能等于指定整数
                if (product % i != 0) {
                    continue;
                }
                get(product / i, newList);
            }
        }
    }

    public static void main(String[] args) {
        long num = 8;
        RecursionDemo02.get(num, new ArrayList<Long>());
//        String str = "4*5*";
//        System.out.println(str.length());
//        System.out.println(str.substring(0,str.length()-1));
//        int num = 8;
//        System.out.println(8/3);
    }
}
